﻿namespace Microsoft.SharePoint.Client
{
    using System;

    public class ClientRequestFailedEventArgs : ClientRequestEventArgs
    {
        private int m_errorCode;
        private object m_errorDetails;
        private string m_errorTypeName;
        private string m_errorValue;
        private System.Exception m_exception;
        private string m_message;
        private string m_stackTrace;

        public ClientRequestFailedEventArgs(ClientRequest request, System.Exception ex) : base(request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }
            ServerException exception = ex as ServerException;
            if (exception != null)
            {
                this.m_message = exception.Message;
                this.m_stackTrace = exception.ServerStackTrace;
                this.m_errorCode = exception.ServerErrorCode;
                this.m_errorValue = exception.ServerErrorValue;
                this.m_errorTypeName = exception.ServerErrorTypeName;
                this.m_errorDetails = exception.ServerErrorDetails;
            }
            else
            {
                this.m_message = ex.Message;
                this.m_stackTrace = ex.StackTrace;
                this.m_errorCode = -1;
            }
            this.m_exception = ex;
        }

        public ClientRequestFailedEventArgs(ClientRequest request, string message, string stackTrace, int errorCode, string errorValue, string errorTypeName, object errorDetails) : base(request)
        {
            this.m_message = message;
            this.m_stackTrace = stackTrace;
            this.m_errorCode = errorCode;
            this.m_errorValue = errorValue;
            this.m_errorTypeName = errorTypeName;
            this.m_errorDetails = errorDetails;
        }

        public int ErrorCode
        {
            get
            {
                return this.m_errorCode;
            }
        }

        public object ErrorDetails
        {
            get
            {
                return this.m_errorDetails;
            }
        }

        public string ErrorTypeName
        {
            get
            {
                return this.m_errorTypeName;
            }
        }

        public string ErrorValue
        {
            get
            {
                return this.m_errorValue;
            }
        }

        public System.Exception Exception
        {
            get
            {
                return this.m_exception;
            }
        }

        public string Message
        {
            get
            {
                return this.m_message;
            }
        }

        public string StackTrace
        {
            get
            {
                return this.m_stackTrace;
            }
        }
    }
}

